package com.ghsc.ghxc.jsb.ui.message.activity

import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.cn.appcore.adapter.PagerAdapter
import com.cn.appcore.base.BaseVMActivity
import com.flyco.tablayout.listener.OnTabSelectListener
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.databinding.ActivitySearchChatBinding
import com.ghsc.ghxc.jsb.ui.message.fragment.SearchGroupChatFragment
import com.ghsc.ghxc.jsb.ui.message.fragment.SearchSingleChatFragment

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.message.activity
 * 类名：SearchChatActivity
 * 创建时间：2024/5/9 18:24
 * 创建人 @author： xiaolin
 * 描述 ：Todo...搜索 好友 或者 群
 */
class SearchChatActivity  : BaseVMActivity<SearchChatViewModel, ActivitySearchChatBinding>() {
    override fun attachLayoutRes(): Int {
        return R.layout.activity_search_chat
    }

    override fun attachVMClass(): Class<SearchChatViewModel>? {
        return SearchChatViewModel::class.java
    }

//    override fun initBar() {
//        super.initBar()
//        mImmersionBar!!.statusBarDarkFont(true).init()
//    }

    private val tabTitles = arrayOf("找人", "找群")
//    var mFragments: MutableList<Fragment> = ArrayList()
//    private var lastIndex = 0


    var mList: MutableList<String> = java.util.ArrayList()
    var mAdapter: PagerAdapter? = null
    private val mFragments: MutableList<Fragment> = java.util.ArrayList()
    override fun initBar() {
        super.initBar()
        mImmersionBar!!.statusBarDarkFont(true).init()
    }
    override fun initView() {
        binding.tabLayout.setTabData(tabTitles)
        for (i in tabTitles.indices) {
            mList.add(tabTitles[i])
        }
        mFragments.clear()
        SearchSingleChatFragment.getInstance()?.let { mFragments.add(it) }
        SearchGroupChatFragment.getInstance()?.let { mFragments.add(it) }
        mAdapter = PagerAdapter(
            supportFragmentManager,
            mList,
            mFragments
        )
        binding.viewPage.adapter = mAdapter
        binding.viewPage.offscreenPageLimit = mList.size - 1
        binding.tabLayout.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                binding.viewPage.currentItem = position
            }

            override fun onTabReselect(position: Int) {

            }

        })
        binding.viewPage.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                binding.tabLayout.currentTab = position
            }

            override fun onPageScrollStateChanged(state: Int) {
            }
        })
    }


    override fun initClickListener() {
        super.initClickListener()
        binding.run {
            imgBtnLeft.setOnClickListener {
                finish()
            }
        }
    }

    override fun initData() {
        super.initData()
    }

}

